package com.sunshine.litemusic.fragment.recommend;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.sunshine.litemusic.R;

import java.util.ArrayList;

/**
 * @author sunshine
 * @date 2020/5/29
 */
public class RecommendAdapter extends RecyclerView.Adapter<RecommendAdapter.RecyclerViewHolder> {

    private ArrayList<RecommendModel.RecommendBean> recommendBeanArrayList;
    private Context context;

    public RecommendAdapter(ArrayList<RecommendModel.RecommendBean> recommendBeanArrayList) {
        this.recommendBeanArrayList = recommendBeanArrayList;
    }

    @NonNull
    @Override
    public RecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        this.context = parent.getContext();
        return new RecyclerViewHolder(LayoutInflater.from(context).inflate(R.layout.item_song, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerViewHolder holder, int position) {
        Glide.with(context)
                .load(recommendBeanArrayList.get(position).getPicUrl())
                .into(holder.imageViewAl);
        holder.songName.setText(recommendBeanArrayList.get(position).getName());
        //holder.alName.setText(recommendBeanArrayList.get(position).getSong().getAlbumBean().getName());
        holder.singerName.setText(recommendBeanArrayList.get(position).getSong().getArtists());
    }

    @Override
    public int getItemCount() {
        return recommendBeanArrayList.size();
    }

    class RecyclerViewHolder extends RecyclerView.ViewHolder{

        ImageView imageViewAl;
        AppCompatTextView songName, singerName, alName;

        public RecyclerViewHolder(@NonNull View itemView) {
            super(itemView);
            imageViewAl = itemView.findViewById(R.id.imageView_al);
            songName = itemView.findViewById(R.id.song_name);
            singerName = itemView.findViewById(R.id.singser_name);
            alName = itemView.findViewById(R.id.al_name);
        }
    }
}
